package Demo06;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/*
对话框

 */
public class MyFont extends JDialog  implements ActionListener {
    //JDialog---对话框 ；
    private  JPanel mainPanel;
    private  JLabel lblZt,lblZx,lblDx;
    private JList<String> listZt,listZx,listDx;
    private  JButton btnOk,btnCancel;
//    private Font,font;

    //实例化；
    public  MyFont( JFrame frame){
        //调用 ；
        super(frame,"字体设置",true);
        mainPanel=new JPanel(null);//空布局
        lblZt=new JLabel("字体: ");
        lblZx=new JLabel("字形: ");
        lblDx=new JLabel("大小: ");
        GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = e.getAvailableFontFamilyNames();
        listZt=new JList<String>(fontNames);

        String[] zx={"常规", "加粗", "倾斜"};
//        listZx=new JList<String>(new String[]{"常规", "加粗", "倾斜"});
        listZx=new JList<String>(zx);

        String[] dx={"1","2","3","4","5","6","7","8","9","10","11",};
//        lblDx= new JLabel(dx);
        listDx=new JList<String>(dx);

        btnOk=new JButton("确定");
        btnCancel=new JButton("取消");

        //大小 位置
        lblZt.setBounds(20,20,80,25);
        lblZx.setBounds(140,20,80,25);
        lblDx.setBounds(260,20,80,25);

        listZt.setBounds(20,50,100,100);
        listZx.setBounds(140,50,100,100);
        listDx.setBounds(260,50,100,100);
        btnOk.setBounds(190,170,60,25);
        btnCancel.setBounds(300,170,60,25);

        //把控件放入容器
        setContentPane(mainPanel);
        mainPanel.add(lblDx);
        mainPanel.add(lblZt);
        mainPanel.add(lblZx);
        mainPanel.add(listDx);
        mainPanel.add(listZt);
        mainPanel.add(btnCancel);
        mainPanel.add(btnOk);
//        mainPanel.add(lblDx);
//        mainPanel.add(lblDx);

        //窗口设置
        setBounds(100,100,380,250);
        setVisible(true);
        setResizable(false);


//        Font font =new Font();
//        this.getFont()frame.get

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource().equals(btnCancel)){
            this.setVisible(false);//隐藏窗口
        }
        if(e.getSource().equals(btnOk)){
//            String fontName=lblZt.

        }
    }
}
